import com.sun.rowset.CachedRowSetImpl;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 *
 * @author tub
 */
public class ExplorePanel extends JPanel
{
    public ExplorePanel()
    {
        tabs = new JTabbedPane();
        tables = new ArrayList<JTable>();

        tabs.addChangeListener(new ChangeListener() {

            public void stateChanged(ChangeEvent e)
            {
            }
        });
        
        add(tabs);
    }

    public void createTab(String string, CachedRowSetImpl set) throws SQLException
    {
        JTable table = new JTable(new ExploreTableModel(set));
        table.setFillsViewportHeight(true);

        tables.add(table);

        tabs.addTab(string, new JScrollPane(table));       
    }

    private void addRemoveButton()
    {
        for (int i = 0; i < tabs.getTabCount(); i++)
        {
            tabs.setTabComponentAt(i, new JButton("x"));
            tabs.getTabComponentAt(i).addMouseListener(new MouseAdapter()
            {
                @Override
                public void mouseReleased(MouseEvent e)
                {
                    
                }
            });
        }
    }

    public void addRow() throws SQLException, IOException
    {
        JTable table = tables.get(tabs.getSelectedIndex());
        ExploreTableModel model = (ExploreTableModel) table.getModel();
        CachedRowSetImpl crs = model.getCrs();

        model.addRow();
        model.fireTableDataChanged();
        table.updateUI();
    }

    private JTabbedPane tabs;
    private ArrayList<JTable> tables;
}
